summaryrefslogtreecommitdiffstats
path: root/src/audio_core/adsp/apps/audio_renderer/command_list_processor.h
blob: 9d6fe185116092448063fcae918c236b75f30650 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-FileCopyrightText: Copyright 2023 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <span>

#include "audio_core/common/common.h"
#include "audio_core/renderer/command/command_list_header.h"
#include "common/common_types.h"

namespace Core {
namespace Memory {
class Memory;
}
class System;
} // namespace Core

namespace AudioCore {
namespace Sink {
class SinkStream;
}

namespace Renderer {
struct CommandListHeader;
}

namespace ADSP::AudioRenderer {

/**
 * A processor for command lists given to the AudioRenderer.
 */
class CommandListProcessor {
public:
    /**
     * Initialize the processor.
     *
     * @param system - The core system.
     * @param buffer - The command buffer to process.
     * @param size   - The size of the buffer.
     * @param stream - The stream to be used for sending the samples.
     */
    void Initialize(Core::System& system, CpuAddr buffer, u64 size, Sink::SinkStream* stream);

    /**
     * Set the maximum processing time for this command list.
     *
     * @param time - The maximum process time.
     */
    void SetProcessTimeMax(u64 time);

    /**
     * Get the remaining command count for this list.
     *
     * @return The remaining command count.
     */
    u32 GetRemainingCommandCount() const;

    /**
     * Set the command buffer.
     *
     * @param buffer - The buffer to use.
     * @param size   - The size of the buffer.
     */
    void SetBuffer(CpuAddr buffer, u64 size);

    /**
     * Get the stream for this command list.
     *
     * @return The stream associated with this command list.
     */
    Sink::SinkStream* GetOutputSinkStream() const;

    /**
     * Process the command list.
     *
     * @param session_id - Session ID for the commands being processed.
     *
     * @return The time taken to process.
     */
    u64 Process(u32 session_id);

    /// Core system
    Core::System* system{};
    /// Core memory
    Core::Memory::Memory* memory{};
    /// Stream for the processed samples
    Sink::SinkStream* stream{};
    /// Header info for this command list
    Renderer::CommandListHeader* header{};
    /// The command buffer
    u8* commands{};
    /// The command buffer size
    u64 commands_buffer_size{};
    /// The maximum processing time allotted
    u64 max_process_time{};
    /// The number of commands in the buffer
    u32 command_count{};
    /// The target sample count for output
    u32 sample_count{};
    /// The target sample rate for output
    u32 target_sample_rate{};
    /// The mixing buffers used by the commands
    std::span<s32> mix_buffers{};
    /// The number of mix buffers
    u32 buffer_count{};
    /// The number of processed commands so far
    u32 processed_command_count{};
    /// The processing start time of this list
    u64 start_time{};
    /// The current processing time for this list
    u64 current_processing_time{};
    /// The end processing time for this list
    u64 end_time{};
    /// Last command list string generated, used for dumping audio commands to console
    std::string last_dump{};
};

} // namespace ADSP::AudioRenderer
} // namespace AudioCore